package com.github.binarywang.demo.wechat.controller;

import com.github.binarywang.demo.wechat.model.Comment;
import com.github.binarywang.demo.wechat.model.CommentKey;
import com.github.binarywang.demo.wechat.service.WxCommentService;
import com.github.binarywang.demo.wechat.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({ "wechat/comment" })
@RestController
public class WxCommentController {
	@Autowired
	private WxCommentService wxCommentService;

	@GetMapping({ "insert" })
	public int insert(Comment comment) {
		return this.wxCommentService.insert(comment);
	}

	@GetMapping({ "list" })
	public String list(Integer start) {
		return JsonUtils.toJson(this.wxCommentService.list(start));
	}

	@GetMapping({ "findByCourseId" })
	public String list(Integer courseId, Integer start) {
		return JsonUtils.toJson(this.wxCommentService.findByCourseId(courseId, start));
	}

	@GetMapping({ "findByOpenId" })
	public String list(String openId, Integer start) {
		return JsonUtils.toJson(this.wxCommentService.findByOpenId(openId, start));
	}

	@GetMapping({ "deleteByPrimaryKey" })
	public int delete(CommentKey commentKey) {
		return this.wxCommentService.deleteByPrimaryKey(commentKey);
	}

	@GetMapping({ "deleteByCourseId" })
	public int delete(Integer courseId) {
		return this.wxCommentService.deleteByCourseId(courseId);
	}
}
